package com.ydy.resource;

import com.ydy.utils.DateUtil;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

/**
 * 服务地址区分配置
 * @author: dy.yin 2022/1/17 8:55
 */
@Component
@ConfigurationProperties(prefix = "server")
@PropertySource("classpath:server-uri-dev.properties")
public class ServerUri {

    private String projectServerUri;//项目的服务uri

    public String getProjectServerUri() {
        return projectServerUri;
    }

    public void setProjectServerUri(String projectServerUri) {
        this.projectServerUri = projectServerUri;
    }


    /**
     * 拼接图片地址
     * @Title: appendImagUrl
     * @author: dy.yin 2022/1/17 11:11
     * @param: [imagePath]   图片相对路径
     * @return: {@link String } 图片完整地址
     */
    public String appendImagUrl(String imagePath){
        //由于浏览器可能存在缓存的情况，所以在这里，我们需要加上时间戳来保证更新后的图片可以及时刷新
        return this.getProjectServerUri() + imagePath + "?t=" + DateUtil.getCurrentDateString(DateUtil.DATE_PATTERN);
    }
}
